package com.ccc3gc.util;

import com.jspsmart.upload.Request;
import com.jspsmart.upload.SmartUpload;
import com.jspsmart.upload.SmartUploadException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UpUtils {
    public static SmartUpload getSmartUpload(ServletConfig servletConfig, HttpServletRequest req, HttpServletResponse resp) throws ServletException {
        SmartUpload su = new SmartUpload();
        su.initialize(servletConfig, req, resp);
        su.setCharset("UTF-8");
        try {
            su.upload();
            su.save("/upfiles");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return su;
    }
}
